package com.ylr.basic.framework.feign.client;

import com.ylr.base.common.tool.Result;
import com.ylr.basic.common.vo.AesVo;
import com.ylr.basic.framework.feign.YbAesBaseClient;
import com.ylr.basic.framework.feign.configuration.ClientConfiguration;
import com.ylr.basic.framework.feign.fallback.YbAesClientFallback;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size;
import java.util.Map;

/**
 * Created by IntelliJ IDEA.
 *
 * @author wyw
 * date: 2023-05-12 10:22:55
 * className: YbAesClient
 * version: 1.0
 * description:
 */
@FeignClient(value = "ylr-basic", contextId = "YbAesClient", path = "/api/aes", fallback = YbAesClientFallback.class,
        configuration = ClientConfiguration.class)
public interface YbAesClient extends YbAesBaseClient {

    /**
     * 明文加密接口
     * @param aesVo 参数对象
     * @return 密文
     */
    @PostMapping("/encrypt")
    Result<String> encrypt(@RequestBody AesVo aesVo);

    /**
     * 明文加密接口
     * 生成十六进制密文
     * @param plainText 明文
     * @return 密文
     */
    @PostMapping("/encrypt/hex")
    Result<String> encryptToHex(@NotBlank(message = "明文不能为空") @RequestParam("plainText") String plainText);

    /**
     * 批量明文加密接口
     * 生成十六进制密文
     * @param paramMap 参数映射
     * @return 结果映射
     */
    @PostMapping("/batch/encrypt/hex")
    Result<Map<?, String>> batchEncryptToHex(@Size(min = 1, message = "参数映射不能为空") @RequestBody Map<?, String> paramMap);

    /**
     * AES密文解密接口
     * @param cipherText 密文
     * @return 明文
     */
    @PostMapping("/decode/hex")
    Result<String> decodeHex(@NotBlank(message = "密文不能为空") @RequestParam("cipherText") String cipherText);

    /**
     * AES密文半解密接口
     * @param cipherText 密文
     * @param start      脱敏开始下标
     * @param end        脱敏结束下标
     * @return 明文
     */
    @PostMapping("/sub/decode/hex")
    Result<String> subDecodeHex(@NotBlank(message = "密文不能为空") @RequestParam("cipherText") String cipherText,
                                @RequestParam(value = "start", required = false) Integer start,
                                @RequestParam(value = "end", required = false) Integer end);

    /**
     * 明文加密接口
     * 生成Base64密文
     * @param plainText 明文
     * @return 密文
     */
    @PostMapping("/encrypt/base64")
    Result<String> encryptToBase64(@NotBlank(message = "明文不能为空") @RequestParam("plainText") String plainText);

    /**
     * AES密文解密接口
     * @param cipherText 密文
     * @return 明文
     */
    @PostMapping("/decode/base64")
    Result<String> decodeBase64(@NotBlank(message = "密文不能为空") @RequestParam("cipherText") String cipherText);

    /**
     * AES密文半解密接口
     * @param cipherText 密文
     * @return 明文
     */
    @PostMapping("/sub/decode/base64")
    Result<String> subDecodeBase64(@NotBlank(message = "密文不能为空") @RequestParam("cipherText") String cipherText,
                                   @RequestParam(value = "start", required = false) Integer start,
                                   @RequestParam(value = "end", required = false) Integer end);

    /**
     * 密文解密接口
     * @param aesVo 参数对象
     * @return 明文
     */
    @PostMapping("/decode")
    Result<String> decode(@RequestBody AesVo aesVo);

    /**
     * 批量密文解密接口
     * @param type     密文类型[1-hex 2-base64]
     * @param paramMap 参数映射集合
     * @return 明文映射集合
     */
    @PostMapping("/batch/decode")
    Result<Map<?, String>> batchDecode(@RequestParam("type") Integer type,
                                       @Size(min = 1, message = "参数映射不能为空")  @RequestBody Map<?, String> paramMap);

}
